/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.creatjobmanage.web;

import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.utils.ApiResultUtils;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.modules.creatjobmanage.entity.CreatJobMes;
import com.lczyfz.campusinfo.modules.creatjobmanage.entity.CreatJobPart;
import com.lczyfz.campusinfo.modules.creatjobmanage.entity.CreatPartProject;
import com.lczyfz.campusinfo.modules.creatjobmanage.service.CreatJobMesService;
import com.lczyfz.campusinfo.modules.creatjobmanage.service.CreatJobPartService;
import com.lczyfz.campusinfo.modules.creatjobmanage.service.CreatJobProjectService;
import com.lczyfz.campusinfo.modules.creatjobmanage.service.CreatPartProjectService;
import com.lczyfz.campusinfo.modules.sys.security.SystemAuthorizingRealm;
import com.lczyfz.campusinfo.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lczyfz.campusinfo.modules.creatjobmanage.entity.CreatJobProject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 园区项目内容和名称Controller
 * @author zms
 * @version 2018-03-26
 */
@Controller
@RequestMapping(value = "api/schoolSource/creatjob")
public class CreatJobApiController extends BaseController {

	@Autowired
	private CreatJobPartService creatJobPartService;

	@Autowired
	private CreatJobProjectService creatJobProjectService;
	@Autowired
	private CreatJobMesService creatJobMesService;

	@Autowired
	private CreatPartProjectService creatPartProjectService;
	@ResponseBody
	@RequestMapping(value = "businessList") //获取创业的业务
	public Map<String, Object> getMes(CreatJobMes jobMes, HttpServletRequest request, HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		Page<CreatJobMes> page = creatJobMesService.findPage(new Page<CreatJobMes>(request, response),jobMes);
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
		map.put("page", page.getList());
		map.put("pageNo", page.getPageNo());
		map.put("count", page.getCount());
		map.put("totalPage", page.getTotalPage());
		return map;
	}
	@RequestMapping(value = "partStype") //获取园区类型
	@ResponseBody
	public Map<String, Object> getJob(CreatJobPart jobPart, HttpServletRequest request, HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		Page<CreatJobPart> page =  creatJobPartService.findPage(new Page<CreatJobPart>(request, response), jobPart);
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
		map.put("page", page.getList());
		map.put("pageNo", page.getPageNo());
		map.put("count", page.getCount());
		map.put("totalPage", page.getTotalPage());
		return map;
	}
	@RequestMapping(value = "ownjobList") //报名自带项目
	@ResponseBody
	public Map<String, Object> getJob(CreatJobProject jobPart, HttpServletRequest request, HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
	//	CreatJobProject creatJobProject = creatJobProjectService.get(jobPart.getId());
		if (StringUtils.isNotBlank(jobPart.getProjectName())) {
			SystemAuthorizingRealm.Principal principal = UserUtils.getPrincipal();
			if(principal!=null){
				jobPart.setUpId(principal.toString());
				creatJobProjectService.save(jobPart);
				map.put("message","报名成功");
			}
            map.put("message","报名失败");
		}
//		Page<CreatJobProject> page =  creatJobProjectService.findPage(new Page<CreatJobProject>(request, response), jobPart);
//		map.put("page", page.getList());
//		map.put("pageNo", page.getPageNo());
//		map.put("count", page.getCount());
//		map.put("totalPage", page.getTotalPage());
		return null;
	}
	@RequestMapping(value = "partjobList") //报名园区项目
	@ResponseBody
	public Map<String, Object> getJob(CreatPartProject jobPart, HttpServletRequest request, HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
		if (StringUtils.isNotBlank(jobPart.getPartName())) {
			SystemAuthorizingRealm.Principal principal = UserUtils.getPrincipal();
			if(principal!=null){
				jobPart.setUpId(principal.toString());
                creatPartProjectService.save(jobPart);
				map.put("message","报名成功");
			}
			map.put("message","报名失败");
		}
//		Page<CreatPartProject> page =  creatPartProjectService.findPage(new Page<CreatPartProject>(request, response), jobPart);
//		creatPartProjectService.save(jobPart);
//		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
//		map.put("page", page.getList());
//		map.put("pageNo", page.getPageNo());
//		map.put("count", page.getCount());
//		map.put("totalPage", page.getTotalPage());
		return map;
	}
}